package com.novanok.papanoeltracking;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;

public class HusoHorarioActivity extends Activity {

    private ArrayList<HusoHorario> lista = null;
    private HusoHorario husoSeleccionado = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_huso_horario);

        this.lista = new ArrayList<HusoHorario>();
        this.lista.add(new HusoHorario("-0800","Alaska Daylight Time, North America","-0800"));
        this.lista.add(new HusoHorario("-0900","Alaska Standard Time, North America","-0900"));
        this.lista.add(new HusoHorario("+0100","Alpha Time Zone, Military","+0100"));
        this.lista.add(new HusoHorario("-0300","Argentina Time, South America","-0300"));
        this.lista.add(new HusoHorario("-0300","Atlantic Daylight Time, North America","-0300"));
        this.lista.add(new HusoHorario("-0400","Atlantic Standard Time, North America","-0400"));
        this.lista.add(new HusoHorario("+1030","Australian Central Daylight Time, Australia","+1030"));
        this.lista.add(new HusoHorario("+0930","Australian Central Standard Time, Australia","+0930"));
        this.lista.add(new HusoHorario("+1100","Australian Eastern Daylight Time, Australia","+1100"));
        this.lista.add(new HusoHorario("+1000","Australian Eastern Standard Time, Australia","+1000"));
        this.lista.add(new HusoHorario("+0900","Australian Western Daylight Time, Australia","+0900"));
        this.lista.add(new HusoHorario("+0800","Australian Western Standard Time, Australia","+0800"));
        this.lista.add(new HusoHorario("+0200","Bravo Time Zone, Military","+0200"));
        this.lista.add(new HusoHorario("+0100","British Summer Time, Europe","+0100"));
        this.lista.add(new HusoHorario("-0500","Central Daylight Time, North America","-0500"));
        this.lista.add(new HusoHorario("+0200","Central European Daylight Time, Europe","+0200"));
        this.lista.add(new HusoHorario("+0200","Central European Summer Time, Europe","+0200"));
        this.lista.add(new HusoHorario("+0100","Central European Time, Europe","+0100"));
        this.lista.add(new HusoHorario("-0600","Central Standard Time, North America","-0600"));
        this.lista.add(new HusoHorario("+0930","Central Standard Time Australia, Australia","+0930"));
        this.lista.add(new HusoHorario("+1030","Central Summer (Daylight) Time, Australia","+1030"));
        this.lista.add(new HusoHorario("+0300","Charlie Time Zone, Military","+0300"));
        this.lista.add(new HusoHorario("+0700","Christmas Island Time, Australia","+0700"));
        this.lista.add(new HusoHorario("+0000","Coordinated Universal Time, Europe","+0000"));
        this.lista.add(new HusoHorario("+0400","Delta Time Zone, Military","+0400"));
        this.lista.add(new HusoHorario("-0400","Eastern Daylight Time, North America","-0400"));
        this.lista.add(new HusoHorario("+0300","Eastern European Daylight Time, Europe","+0300"));
        this.lista.add(new HusoHorario("+0300","Eastern European Summer Time, Europe","+0300"));
        this.lista.add(new HusoHorario("+0200","Eastern European Time, Europe","+0200"));
        this.lista.add(new HusoHorario("-0500","Eastern Standard Time, North America","-0500"));
        this.lista.add(new HusoHorario("+1000","Eastern Standard Time Australia, Australia","+1000"));
        this.lista.add(new HusoHorario("+0500","Echo Time Zone, Military","+0500"));
        this.lista.add(new HusoHorario("+0600","Foxtrot Time Zone, Military","+0600"));
        this.lista.add(new HusoHorario("+0700","Golf Time Zone, Military","+0700"));
        this.lista.add(new HusoHorario("+0000","Greenwich Mean Time, Europe","+0000"));
        this.lista.add(new HusoHorario("-0900","Hawaii-Aleutian Daylight Time, North America","-0900"));
        this.lista.add(new HusoHorario("-0100","Hawaii-Aleutian Standard Time, North America","-0100"));
        this.lista.add(new HusoHorario("-0300","Heure Avancée de l'Atlantique, North America","-0300"));
        this.lista.add(new HusoHorario("-0400","Heure Avancée de l'Est, North America","-0400"));
        this.lista.add(new HusoHorario("-0230","Heure Avancée de Terre-Neuve, North America","-0230"));
        this.lista.add(new HusoHorario("-0600","Heure Avancée des Rocheuses, North America","-0600"));
        this.lista.add(new HusoHorario("-0500","Heure Avancée du Centre, North America","-0500"));
        this.lista.add(new HusoHorario("-0700","Heure Avancée du Pacifique, North America","-0700"));
        this.lista.add(new HusoHorario("-0800","Heure Avancée du Yukon, North America","-0800"));
        this.lista.add(new HusoHorario("-0400","Heure Normale de l'Atlantique, North America","-0400"));
        this.lista.add(new HusoHorario("-0500","Heure Normale de l'Est, North America","-0500"));
        this.lista.add(new HusoHorario("-0330","Heure Normale de Terre-Neuve, North America","-0330"));
        this.lista.add(new HusoHorario("-0700","Heure Normale des Rocheuses, North America","-0700"));
        this.lista.add(new HusoHorario("-0600","Heure Normale du Centre, North America","-0600"));
        this.lista.add(new HusoHorario("-0800","Heure Normale du Pacifique, North America","-0800"));
        this.lista.add(new HusoHorario("-0900","Heure Normale du Yukon, North America","-0900"));
        this.lista.add(new HusoHorario("+0800","Hotel Time Zone, Military","+0800"));
        this.lista.add(new HusoHorario("+0900","India Time Zone, Military","+0900"));
        this.lista.add(new HusoHorario("+0100","Irish Summer Time, Europe","+0100"));
        this.lista.add(new HusoHorario("+1000","Kilo Time Zone, Military","+1000"));
        this.lista.add(new HusoHorario("+1100","Lima Time Zone, Military","+1100"));
        this.lista.add(new HusoHorario("+1200","Mike Time Zone, Military","+1200"));
        this.lista.add(new HusoHorario("+0200","Mitteleuroäische Sommerzeit, Europe","+0200"));
        this.lista.add(new HusoHorario("+0100","Mitteleuropäische Zeit, Europe","+0100"));
        this.lista.add(new HusoHorario("-0600","Mountain Daylight Time, North America","-0600"));
        this.lista.add(new HusoHorario("-0700","Mountain Standard Time, North America","-0700"));
        this.lista.add(new HusoHorario("-0230","Newfoundland Daylight Time, América Norte","-0230"));
        this.lista.add(new HusoHorario("-0330","Newfoundland Standard Time, América Norte","-0330"));
        this.lista.add(new HusoHorario("+1130","Norfolk (Island) Time, Australia","+1130"));
        this.lista.add(new HusoHorario("+0000","November Time Zone, Military","+0000"));
        this.lista.add(new HusoHorario("-0200","Oscar Time Zone, Military","-0200"));
        this.lista.add(new HusoHorario("-0700","Pacific Daylight Time, América Norte","-0700"));
        this.lista.add(new HusoHorario("-0800","Pacific Standard Time, América Norte","-0800"));
        this.lista.add(new HusoHorario("-0300","Papa Time Zone, Military","-0300"));
        this.lista.add(new HusoHorario("-0400","Quebec Time Zone, Military","-0400"));
        this.lista.add(new HusoHorario("-0500","Romeo Time Zone, Military","-0500"));
        this.lista.add(new HusoHorario("-0600","Sierra Time Zone, Military","-0600"));
        this.lista.add(new HusoHorario("-0700","Tango Time Zone, Military","-0700"));
        this.lista.add(new HusoHorario("-0800","Uniform Time Zone, Military","-0800"));
        this.lista.add(new HusoHorario("-0900","Victor Time Zone, Military","-0900"));
        this.lista.add(new HusoHorario("+0100","Western European Daylight Time, Europe","+0100"));
        this.lista.add(new HusoHorario("+0100","Western European Summer Time, Europe","+0100"));
        this.lista.add(new HusoHorario("+0000","Western European Time, Europe","+0000"));
        this.lista.add(new HusoHorario("+0800","Western Standard Time, Australia","+0800"));
        this.lista.add(new HusoHorario("-0900","Western Summer(Daylight) Time, Australia","-0900"));
        this.lista.add(new HusoHorario("-1000","Whiskey Time Zone, Military","-1000"));
        this.lista.add(new HusoHorario("-1100","X-ray Time Zone, Military","-1100"));
        this.lista.add(new HusoHorario("-1200","Yankee Time Zone, Military","-1200"));
        this.lista.add(new HusoHorario("+0000","Zulu Time Zone, Military","+0000"));
        this.lista.add(new HusoHorario("+0100","Alpha (zona), Militar","+0100"));
        this.lista.add(new HusoHorario("+0200","Bravo (zona), Militar","+0200"));
        this.lista.add(new HusoHorario("+0300","Charlie (zona), Militar","+0300"));
        this.lista.add(new HusoHorario("+0400","Delta (zona), Militar","+0400"));
        this.lista.add(new HusoHorario("+0500","Echo (zona), Military","+0500"));
        this.lista.add(new HusoHorario("+0600","Foxtrot (zona), Militar","+0600"));
        this.lista.add(new HusoHorario("+0700","Golf (zona), Militar","+0700"));
        this.lista.add(new HusoHorario("-0900","Hawaii-Aleutianas (Verano), América Norte","-0900"));
        this.lista.add(new HusoHorario("-0100","Hawaii-Aleutianas Standard, América Norte","-0100"));
        this.lista.add(new HusoHorario("-0600","Hora Avanzada de Rocheuses, América Norte","-0600"));
        this.lista.add(new HusoHorario("-0300","Hora Avanzada del Atlantico, América Norte","-0300"));
        this.lista.add(new HusoHorario("-0500","Hora Avanzada del Centro, América Norte","-0500"));
        this.lista.add(new HusoHorario("-0400","Hora Avanzada del Este, América Norte","-0400"));
        this.lista.add(new HusoHorario("-0700","Hora Avanzada del Pacífico, América Norte","-0700"));
        this.lista.add(new HusoHorario("-0230","Hora Avanzada del Terra-Nova, América Norte","-0230"));
        this.lista.add(new HusoHorario("-0800","Hora Avanzada del Yukon, América Norte","-0800"));
        this.lista.add(new HusoHorario("+0930","Hora Central Australia (Estandar), Australia","+0930"));
        this.lista.add(new HusoHorario("+1030","Hora Central Australia (Verano), Australia","+1030"));
        this.lista.add(new HusoHorario("-0900","Hora de Alaska (Estandar), América Norte","-0900"));
        this.lista.add(new HusoHorario("-0800","Hora de Alaska (Verano), América Norte","-0800"));
        this.lista.add(new HusoHorario("-0300","Hora de Argentina, Suramérica","-0300"));
        this.lista.add(new HusoHorario("-0330","Hora de Newfoundland (Estandar), América Norte","-0330"));
        this.lista.add(new HusoHorario("-0700","Hora de Rocheuses (Normal), América Norte","-0700"));
        this.lista.add(new HusoHorario("-0330","Hora de Terra-Nova (Normal), América Norte","-0330"));
        this.lista.add(new HusoHorario("+0100","Hora de Verano Gran Bretaña, Europa","+0100"));
        this.lista.add(new HusoHorario("-0400","Hora del Atlantico (Estandar), América Norte","-0400"));
        this.lista.add(new HusoHorario("-0400","Hora del Atlantico (Normal), América Norte","-0400"));
        this.lista.add(new HusoHorario("-0300","Hora del Atlantico (Verano), América Norte","-0300"));
        this.lista.add(new HusoHorario("-0600","Hora del Centro, América Norte","-0600"));
        this.lista.add(new HusoHorario("-0600","Hora del Centro (Normal), América Norte","-0600"));
        this.lista.add(new HusoHorario("-0500","Hora del Centro (Verano), América Norte","-0500"));
        this.lista.add(new HusoHorario("+0930","Hora del Centro Australia, Australia","+0930"));
        this.lista.add(new HusoHorario("+1030","Hora del Centro Australia (Verano), Australia","+1030"));
        this.lista.add(new HusoHorario("+0100","Hora del Centro Europa, Europa","+0100"));
        this.lista.add(new HusoHorario("+0200","Hora del Centro Europa (Verano), Europa","+0200"));
        this.lista.add(new HusoHorario("+0200","Hora del Centro Europa (Verano), Europa","+0200"));
        this.lista.add(new HusoHorario("-0500","Hora del Este (Estandar), América Norte","-0500"));
        this.lista.add(new HusoHorario("-0500","Hora del Este (Normal), América Norte","-0500"));
        this.lista.add(new HusoHorario("-0400","Hora del Este (Verano), América Norte","-0400"));
        this.lista.add(new HusoHorario("+1000","Hora del Este Australia, Australia","+1000"));
        this.lista.add(new HusoHorario("+1100","Hora del Este Australia (Verano), Australia","+1100"));
        this.lista.add(new HusoHorario("+1000","Hora del Este Australian (Estandar), Australia","+1000"));
        this.lista.add(new HusoHorario("+0200","Hora del Este Europa, Europa","+0200"));
        this.lista.add(new HusoHorario("+0300","Hora del Este Europa (Primavera), Europa","+0300"));
        this.lista.add(new HusoHorario("+0300","Hora del Este Europa (Verano), Europa","+0300"));
        this.lista.add(new HusoHorario("+0800","Hora del Oeste Australia (Estandar), Australia","+0800"));
        this.lista.add(new HusoHorario("+0800","Hora del Oeste Australia (Estandar), Australia","+0800"));
        this.lista.add(new HusoHorario("+0900","Hora del Oeste Australia (Verano), Australia","+0900"));
        this.lista.add(new HusoHorario("+0900","Hora del Oeste Australia (Verano), Australia","+0900"));
        this.lista.add(new HusoHorario("+0000","Hora del Oeste Europa, Europa","+0000"));
        this.lista.add(new HusoHorario("+0100","Hora del Oeste Europa (Verano), Europa","+0100"));
        this.lista.add(new HusoHorario("+0100","Hora del Oeste Europa (Verano), Europa","+0100"));
        this.lista.add(new HusoHorario("-0800","Hora del Pacifico (Estandar), América Norte","-0800"));
        this.lista.add(new HusoHorario("-0800","Hora del Pacífico (Normal), América Norte","-0800"));
        this.lista.add(new HusoHorario("-0700","Hora del Pacifico (Verano), América Norte","-0700"));
        this.lista.add(new HusoHorario("-0900","Hora Yukon (Normal), América Norte","-0900"));
        this.lista.add(new HusoHorario("+0800","Hotel (zona), Militar","+0800"));
        this.lista.add(new HusoHorario("+0900","India (zona), Militar","+0900"));
        this.lista.add(new HusoHorario("+0100","Irish Summer, Europa","+0100"));
        this.lista.add(new HusoHorario("+0700","Isla Navidad, Australia","+0700"));
        this.lista.add(new HusoHorario("+1130","Islas Norfolk, Australia","+1130"));
        this.lista.add(new HusoHorario("+1000","Kilo (zona), Militar","+1000"));
        this.lista.add(new HusoHorario("+1100","Lima (zona), Militar","+1100"));
        this.lista.add(new HusoHorario("+0000","Meridiando de Greenwich, Europa","+0000"));
        this.lista.add(new HusoHorario("+1200","Mike (zona), Militar","+1200"));
        this.lista.add(new HusoHorario("+0200","Mitteleuroäische Sommerzeit, Europa","+0200"));
        this.lista.add(new HusoHorario("+0100","Mitteleuropäische Zeit, Europa","+0100"));
        this.lista.add(new HusoHorario("-0700","Montañas (Estandar), América Norte","-0700"));
        this.lista.add(new HusoHorario("-0600","Montañas (Verano), América Norte","-0600"));
        this.lista.add(new HusoHorario("-0230","Newfoundland (Verano), América Norte","-0230"));
        this.lista.add(new HusoHorario("+0000","Noviembre  (zona), Militar","+0000"));
        this.lista.add(new HusoHorario("-0200","Oscar (zona), Militar","-0200"));
        this.lista.add(new HusoHorario("-0300","Papa (zona), Militar","-0300"));
        this.lista.add(new HusoHorario("-0400","Quebec (zona), Militar","-0400"));
        this.lista.add(new HusoHorario("-0500","Romeo (zona), Militar","-0500"));
        this.lista.add(new HusoHorario("-0600","Sierra (zona), Militar","-0600"));
        this.lista.add(new HusoHorario("-0700","Tango (zona), Militar","-0700"));
        this.lista.add(new HusoHorario("+0000","Tiempo Universal Cordinado, Europa","+0000"));
        this.lista.add(new HusoHorario("-0800","Uniform (zona), Militar","-0800"));
        this.lista.add(new HusoHorario("-0900","Victor (zona), Militar","-0900"));
        this.lista.add(new HusoHorario("-1000","Whiskey (zona), Militar","-1000"));
        this.lista.add(new HusoHorario("-1100","X-Ray (zona), Militar","-1100"));
        this.lista.add(new HusoHorario("-1200","Yankee (zona), Militar","-1200"));
        this.lista.add(new HusoHorario("+0000","Zulu (zona), Militar","+0000"));

        (( ListView ) HusoHorarioActivity.this.findViewById( R.id.lstCarpetas )).setAdapter(
                new ListaHusoHorarioAdapter( HusoHorarioActivity.this, this.lista ) );

        setClickLista();
    }

    @Override
    public boolean onCreateOptionsMenu( Menu menu ) {
        getMenuInflater().inflate( R.menu.menu_item, menu );
        return true;
    }

    @Override
    public boolean onOptionsItemSelected( MenuItem item ) {
        switch ( item.getItemId() ) {
            case R.id.aceptar_cuenta_item:
                this.aceptar();
                return true;

            case R.id.cancelar_cuenta_item:
                this.cancelar();
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private void aceptar(){
        if ( this.husoSeleccionado != null ) {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
            sharedPref.edit().putString("gmt", this.husoSeleccionado.getValor()).apply();
            Mensaje.getMensaje().mostrarInformacion( this, "Debe Reiniciar la Aplicacion para que los cambios se apliquen.", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    finish();
                }
            });
        }
    }

    private void cancelar(){
        finish();
    }

    private void setClickLista(){
        ListView lv = ( ListView )findViewById( R.id.lstCarpetas );

        lv.setOnItemClickListener( new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick( AdapterView<?> adapterView, View view, int i, long l ) {
                view.setSelected( true );

                ListaHusoHorarioAdapter adapter = ( ListaHusoHorarioAdapter )( ( ListView ) findViewById( R.id.lstCarpetas ) ).getAdapter();
                HusoHorario toRemove = adapter.getItem( ( ( ListView ) findViewById( R.id.lstCarpetas ) ).getPositionForView( view ) );
                HusoHorarioActivity.this.husoSeleccionado = toRemove;
            }
        });
    }
}
